package StudyCode.summary.BufferAndChannel;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.EnumSet;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UsingWritableByteChannelWriteFile {
	public static void main(String[] args) {
		Path path = Paths.get("E:\\Copy", "1.txt");
		try (WritableByteChannel writableByteChannel = Files.newByteChannel(path,
				EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.APPEND))) {
			ByteBuffer buffer = ByteBuffer.wrap("WritableByteChannel Demo!".getBytes());
			int write = writableByteChannel.write(buffer);
			System.out.println("写入字节数: " + write);
			buffer.clear();
		} catch (IOException ex) {
			System.err.println(ex);
		}
	}
}
